/*
 * Copyright 2009 rashaguo <rashaguo@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#include "httplikeservice.h"

#include "webserver/webserver.h"
#include "nat/natnetwork.h"
#include "utils/logger.h"

HttpLikeService::HttpLikeService()
:Service()
{
    LOG_DEBUG("init http like service");
    m_webServer = new WebServerWrapper();

    m_serviceName = "Webserver";
    m_localPort= m_webServer->getServerPort();
}

HttpLikeService::~HttpLikeService()
{
    delete m_webServer;
}

void HttpLikeService::run()
{
    if(m_webServer->isRunning()) return;
    //Error handler TBD
    m_webServer->start();
}

void HttpLikeService::go()
{
    if(m_webServer->isRunning()) return;
    //Error handler TBD
    m_webServer->start();
}

void HttpLikeService::process(unsigned int session_id,
                        std::string request_id,
                        std::string request_type,
                        std::string request)
{
}

void HttpLikeService::stop()
{
    if(m_webServer->isRunning())
    {
        m_webServer->stop();
    }
}

bool HttpLikeService::isServerRunning()
{
    return m_webServer->isRunning();
}

std::string HttpLikeService::getServiceName()
{
    return m_serviceName;
}

std::string HttpLikeService::getServerLocalIP()
{
    m_localIP = NatNetwork::getInstance()->getLocalIP();
    return m_localIP;
}

std::string HttpLikeService::getServerLocalPort()
{
    return m_localPort;
}

std::string HttpLikeService::getServerNatIP()
{
    return NatNetwork::getInstance()->getNatIP();
}

std::string HttpLikeService::getServerNatPort()
{
    return NatNetwork::getInstance()->getNatPort(m_localPort);
}

bool HttpLikeService::isNat()
{
    return NatNetwork::getInstance()->isInNat();
}
